from unittest import TestCase

import pymysql
from ddt import ddt, data, unpack
from selenium import webdriver

import Data
import Operation


@ddt
class Test_Sign_Up(TestCase):
    @data(*Data.SignUpDate.right)
    @unpack
    def test_signup(self, name, pwd, repwd, expect):
        connect = pymysql.connect(host='localhost', user='root', password='root', database='finance')
        cursor = connect.cursor()
        sql = "delete from user where username='wangwu';"
        print(sql)
        cursor.execute(sql)
        connect.commit()

        driver = webdriver.Chrome()
        driver.get("http://localhost:90")
        signup = Operation.SignUp()
        signup.signup(name, pwd, repwd, driver)

        url = signup.signup_result(driver)
        if url == 'http://localhost:90/':
            result = '返回登陆页面'
        self.assertEqual(expect, result)

    @data(*Data.SignUpDate.wrongname)
    @unpack
    def test_wrong_name(self, name, pwd, repwd, expect):
        driver = webdriver.Chrome()
        driver.get("http://localhost:90")
        signup = Operation.SignUp()
        signup.wrong_name(name, pwd, repwd, driver)

        url = signup.wrong_name_result(driver)
        if url != 'http://localhost:90/':
            result = '注册失败'
        self.assertEqual(expect, result)

    @data(*Data.SignUpDate.wrongpwd)
    @unpack
    def test_wrong_pwd(self, name, pwd, repwd, expect):
        driver = webdriver.Chrome()
        driver.get("http://localhost:90")
        signup = Operation.SignUp()
        signup.wrong_repwd(name, pwd, repwd, driver)

        url, result = signup.wrong_repwd_result(driver)
        self.assertEqual(expect, result)
